package cn.getech.data.development.service.impl;

import cn.getech.data.development.constant.PermissionTypeEnum;
import cn.getech.data.development.entity.ConfConnect;
import cn.getech.data.development.mapper.ConfConnectMapper;
import cn.getech.data.development.service.ConfConnectApiService;
import cn.getech.data.development.service.ConfConnectService;
import cn.getech.data.development.utils.DataPermissionUtil;
import cn.getech.data.development.vo.ConfConnectApiVo;
import cn.getech.data.intelligence.common.utils.Query;
import cn.getech.system.center.utils.ShiroUtils;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName ConfConnectApiServiceImpl
 * @Description TODO
 * @Author Getech
 * @Date 2020/12/24 13:50
 */
@Service

public class ConfConnectApiServiceImpl implements ConfConnectApiService {
    @Autowired
    private ConfConnectMapper confConnectMapper;

    @Autowired
    private ConfConnectService confConnectService;

    @Override
    public List<ConfConnectApiVo> queryAuthConfList() {
        List<ConfConnectApiVo> allConfConnectlist=new ArrayList<>();
        Map params=new HashMap();
        params.put("create_per", ShiroUtils.getUserId().intValue());
        params.put("sidx", "id");
        params.put("order", "desc");
        params.put("page", "1");
        params.put("limit", "2000");

        //当前登录人
        DataPermissionUtil.putDataFilter(params,
                PermissionTypeEnum.RESOURCE.getType(), PermissionTypeEnum.QUERY.getType());
//        confConnectService.setTenantParams(params, PermissionTypeEnum.RESOURCE.getType(),PermissionTypeEnum.QUERY.getType(),ShiroUtils.getTenantId());
        IPage<ConfConnect> page = this.confConnectMapper.listNoRelation((Page<ConfConnect>) new Query<ConfConnect>().getPage(params), params);
        List<ConfConnect>  subList=page.getRecords()!=null?page.getRecords():new ArrayList<>();
        allConfConnectlist= subList.stream().map(e->{
            ConfConnectApiVo  confConnectApiVo=new ConfConnectApiVo();
            BeanUtil.copyProperties(e,confConnectApiVo);
            return confConnectApiVo;
        }).collect(Collectors.toList());
        return allConfConnectlist;

    }
}
